<%@ page import="gfo.Match" %>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <meta name="layout" content="main"/>
    <g:set var="entityName" value="${message(code: 'match.label', default: 'Match')}"/>
    <title><g:message code="default.create.label" args="[entityName]"/></title>
</head>

<body>

<div class="body">
    <h1><g:message code="default.create.label" args="[entityName]"/></h1>
    <g:if test="${flash.message}">
        <div class="message">${flash.message}</div>
    </g:if>
    <g:hasErrors bean="${matchInstance}">
        <div class="errors">
            <g:renderErrors bean="${matchInstance}" as="list"/>
        </div>
    </g:hasErrors>
    <!--There's nothing particularly impressive about this view, with the exception that we can see
    here that the form requires information that is intuitive to encapsulate a Match in terms of. The
    problem is that some of this data goes into the Match itself, while some of it goes into the
    respective Matchships. The parsing fun happens in MatchController, under the save action.-->
    <g:form action="save">
        <div class="dialog">
            <table>
                <tbody>

                <tr class="prop">
                    <td valign="top" class="name">
                        <label for="tournament">Tournament</label>
                    </td>
                    <td valign="top" class="value ${hasErrors(bean: matchInstance, field: 'tournament', 'errors')}">
                        <g:select name="tournament.id" from="${gfo.Tournament.list()}" optionKey="id"
                                  value="${matchInstance?.tournament?.id}"/>
                    </td>
                </tr>

                <tr class="prop">
                    <td valign="top" class="name">
                        <label for="winner">Winner:</label>
                    </td>
                    <td valign="top" class="value ${hasErrors(bean: matchInstance, field: 'winner', 'errors')}">
                        <g:select name="winner.id" from="${gfo.Player.list()}" optionKey="id"
                                  value="Player.id"/>
                    </td>
                </tr>

                <tr class="prop">
                    <td valign="top" class="name">
                        <label for="char1">Character (1):</label>
                    </td>
                    <td valign="top" class="value ${hasErrors(bean: matchInstance, field: 'winnerChar', 'errors')}">
                        <g:select name="winnerChar.id" from="${gfo.Fighter.list()}" optionKey="id"
                                  value="Fighter.id" noSelection="['':'Unknown']"/>
                    </td>
                </tr>

                <tr class="prop">
                    <td valign="top" class="name">
                        <label for="loser">Loser:</label>
                    </td>
                    <td valign="top" class="value ${hasErrors(bean: matchInstance, field: 'loser', 'errors')}">
                        <g:select name="loser.id" from="${gfo.Player.list()}" optionKey="id"
                                  value="Player.id"/>
                    </td>
                </tr>

                <tr class="prop">
                    <td valign="top" class="name">
                        <label for="char2">Character (2)</label>
                    </td>
                    <td valign="top" class="value ${hasErrors(bean: matchInstance, field: 'loserChar', 'errors')}">
                        <g:select name="loserChar.id" from="${gfo.Fighter.list()}" optionKey="id"
                                  value="Fighter.id" noSelection="['':'Unknown']"/>
                    </td>
                </tr>

                <tr class="prop">
                    <td valign="top" class="name">
                        <label for="stage">Stage</label>
                    </td>
                    <td valign="top" class="value ${hasErrors(bean: matchInstance, field: 'stage', 'errors')}">
                        <g:select name="stage.id" from="${gfo.Stage.list()}" optionKey="id"
                                  value="${matchInstance?.stage?.id}" noSelection="['':'Unknown']"/>
                    </td>
                </tr>

                <tr class="prop">
                    <td valign="top" class="name">
                        <label for="bracket">Bracket:</label>
                    </td>
                    <td valign="top" class="value ${hasErrors(bean: matchInstance, field: 'bracket', 'errors')}">
                        <g:select name="bracket.id" from="${gfo.Bracket.list()}" optionKey="id"
                                  value="${matchInstance?.bracket?.id}"/>
                    </td>
                </tr>

                <tr class="prop">
                    <td valign="top" class="name">
                        <label for="vidURL">Video?</label>
                    </td>
                    <td valign="top" class="value ${hasErrors(bean: matchInstance, field: 'vidURL', 'errors')}">
                        <g:textField name="vidURL" value="${matchInstance?.vidURL}" />
                    </td>
                </tr>

                </tbody>
            </table>
        </div>

        <div class="buttons">
            <span class="button"><g:submitButton name="create" class="save"
                                                 value="${message(code: 'default.button.create.label', default: 'Create')}"/></span>
        </div>
    </g:form>
</div>
</body>
</html>
